package com.office.automate.servlet.frameworks;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.office.automate.configuration.property.DatagridPageConfiguration;
import com.office.automate.frontier.utility.DataConversionUtility;
import com.office.automate.model.employee.Employee;
import com.office.automate.service.def.employee.EmployeeService;
import com.office.automate.service.impl.employee.EmployeeServiceImplementer;

/**
 * Servlet implementation class DataGridComponentOtherActionServlet
 */
@WebServlet("/DataGridComponentOtherActionServlet")
public class DataGridComponentOtherActionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DataGridComponentOtherActionServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/jsp/HomePage.jsp");;
		String datagridPageID = (String) request.getParameter("DataGridPageID");
		try {
			if (DatagridPageConfiguration.EMPLOYEE_DETAILS.equalsIgnoreCase(datagridPageID)) {
				dispatcher = getServletContext().getRequestDispatcher("/jsp/employee/ViewEmployee.jsp");
				EmployeeService employeeService = new EmployeeServiceImplementer();
				Employee employee = employeeService.getEmployeeDetails(new DataConversionUtility().convertToLong(request.getParameter("Field1")));
				request.setAttribute("Employee", employee);
			}
			dispatcher.forward(request, response);
		} catch (Exception e) {
			request.setAttribute("OperationalError", e);
			dispatcher.forward(request, response);	
		}
	}

}
